import os
from common.base import *

# 打开浏览器
driver = webdriver.Chrome()
driver.maximize_window()
# 获取本地地址
url = 'file:///' + os.path.abspath('html') + '/注册实例.html'
driver.get(url)
# 准备数据
user_info = {'user': 'admin', 'pw': '1234', 'tel': '12345678901', 'email': 'admin@qq.com'}

# TODO 1注册用户界面
# 定位账号,并输入id:user
driver.find_element(By.ID, 'user').send_keys(user_info['user'])
# 定位密码,并输入id:password
driver.find_element(By.ID, 'password').send_keys(user_info['pw'])
# 定位电话号码,并输入id:tel
driver.find_element(By.ID, 'tel').send_keys(user_info['tel'])
# 定位邮箱,并输入id:email
driver.find_element(By.ID, 'email').send_keys(user_info['email'])
# 定位注册按钮,并点击
sleep(2)
driver.find_element(By.XPATH, '//*[@id="zc"]/fieldset/button').click()
# 切换到注册用户A
driver.switch_to.frame('myframe1')

# TODO 2注册用户A
# 定位账号,并输入id:userA
driver.find_element(By.ID, 'userA').send_keys(user_info['user'])
# 定位密码,并输入id:passwordA
driver.find_element(By.ID, 'passwordA').send_keys(user_info['pw'])
# 定位电话号码,并输入id:telA
driver.find_element(By.ID, 'telA').send_keys(user_info['tel'])
# 定位邮箱,并输入id:emailA
driver.find_element(By.ID, 'emailA').send_keys(user_info['email'])
# 定位注册A按钮,//*[@id="zc"]/fieldset/button
sleep(2)
driver.find_element(By.XPATH, '//*[@id="zc"]/fieldset/button').click()
# # 切换到注册用户B
driver.switch_to.parent_frame()
driver.switch_to.frame('myframe2')

# TODO 3注册用户B
# 定位账号,并输入id:userB
driver.find_element(By.ID, 'userB').send_keys(user_info['user'])
# 定位密码,并输入id:passwordB
driver.find_element(By.ID, 'passwordB').send_keys(user_info['pw'])
# 定位电话号码,并输入id:telB
driver.find_element(By.ID, 'telB').send_keys(user_info['tel'])
# 定位邮箱,并输入id:emailB
driver.find_element(By.ID, 'emailB').send_keys(user_info['email'])
# 定位注册按钮,//*[@id="zc"]/fieldset/button
sleep(2)
driver.find_element(By.XPATH, '//*[@id="zc"]/fieldset/button').click()

# 关闭浏览器
sleep(5)
driver.quit()
